cmake_minimum_required(VERSION 3.21)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(dspSimulator LANGUAGES C CXX)

find_package(LLVM REQUIRED CONFIG)

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})

if (PROJECT_BINARY_DIR STREQUAL PROJECT_SOURCE_DIR)
    message(WARNING "The binary directory of CMake cannot be the same as source directory!")
endif ()

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif ()

file(GLOB_RECURSE srcs CONFIGURE_DEPENDS src/* main.cpp)

add_compile_definitions(PRINT_FUNC)

add_executable(simulatorV1 ${srcs})

target_include_directories(simulatorV1 PUBLIC include)

llvm_map_components_to_libnames(llvm_libs support core irreader mcjit x86AsmParser x86Info x86CodeGen)

# Link against LLVM libraries
target_link_libraries(simulatorV1 ${llvm_libs})